import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:full_display/common/qxp_color.dart';
import 'package:full_display/common/qxp_style.dart';
import 'package:full_display/provide/button_list_provider.dart';
import 'package:full_display/unit/asset_utils/asset_utils.dart';
import 'package:full_display/unit/screen/screen_utility.dart';
import 'package:full_display/unit/widgets/drawer/drawer_widget.dart';
import 'package:full_display/unit/widgets/widget_button_list.dart';
import 'package:full_display/unit/widgets/widget_dialog/bluetooth_setting_dialog.dart';
import 'package:full_display/unit/widgets/widget_dialog/clock_dialog.dart';
import 'package:full_display/unit/widgets/widget_dialog/widget_dialog.dart';
import 'package:full_display/unit/widgets/widget_dialog/wifi_device_setting_dialog.dart';
import 'package:full_display/unit/widgets/widget_dialog/wifi_setting_dialog.dart';
import 'package:full_display/unit/widgets/widget_media_list.dart';
import 'package:full_display/unit/widgets/widget_switch.dart';
import 'package:provider/provider.dart';

final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey();

class CloudsDeviceDetailPage extends StatefulWidget {
  const CloudsDeviceDetailPage({super.key});

  @override
  State<CloudsDeviceDetailPage> createState() => _CloudsDeviceDetailPageState();
}

class _CloudsDeviceDetailPageState extends State<CloudsDeviceDetailPage> {
  late ButtonListProvider _btnListData;
  TextEditingController passwordController = TextEditingController();
  TextEditingController wifiNameController = TextEditingController();
  TextEditingController nameController = TextEditingController();
  @override
  Widget build(BuildContext context) {
    _btnListData = context.watch<ButtonListProvider>();
    return Scaffold(
      backgroundColor: ColorPlate.background,
      resizeToAvoidBottomInset: false,
      drawer: DrawerWidget(),
      key: _scaffoldKey,
      appBar: AppBar(
        backgroundColor: ColorPlate.background,
        elevation: 0,
        title: Center(
          child: Text(
            '设备详情',
            textAlign: TextAlign.center,
            style: StandardTextStyle.textWhite16BoldStyle,
          ),
        ),
        leading: IconButton(
          icon: Image.asset(
              height: 20.0.H, width: 20.0.W, AssetUtils.getAsset2Image("back")),
          onPressed: () {
            Navigator.of(context).pop();
          },
        ),
        actions: [
          IconButton(
            icon: Image.asset(
                height: 20.0.H,
                width: 20.0.W,
                AssetUtils.getAsset2Image("icon_fold")),
            onPressed: () {
              _scaffoldKey.currentState?.openDrawer();
            },
          ),
          IconButton(
            icon: Image.asset(
              height: 24.0.H,
              width: 24.0.W,
              AssetUtils.getAsset2Image("icon_add"),
            ),
            onPressed: () {
              print("Search Pressed");
            },
          ),
        ],
      ),
      body: Padding(
        padding: EdgeInsets.all(20.0.W),
        child: Center(
          child: Column(
            children: [
              Text(
                'S6-6C2A2858AC',
                textAlign: TextAlign.center,
                style: StandardTextStyle.textWhite24BoldStyle,
              ),
              Container(
                height: 30.0.H,
              ),
              ButtonListWidget(
                btnList: _btnListData.btnList,
                tapAction: settingdialog,
                isBg: true,
              ),
              Container(
                height: 10.0.H,
              ),
              SwitchWidget(
                tapAction: switchValue,
                value: false,
              ),
              Container(
                height: 10.0.H,
              ),
              MedisListWidget(
                info: "清空视频",
                list: [],
                h: 200,
                clearData: () {},
              ),
            ],
          ),
        ),
      ),
    );
  }

  //WiFi 设置方法
  void settingdialog(int index, BuildContext context) {
    if (index == 0) {
      showDialog(
        barrierDismissible: false,
        context: context,
        builder: (context) {
          return DialogWidget(
            contentWidget: WIFIDeviceSettingDialog(
              okBtnTap: () {
                print(
                  "输入框中的文字为:${passwordController.text}",
                );
              },
              nameVc: wifiNameController,
              pwdVc: passwordController,
              cancelBtnTap: () {},
            ),
          );
        },
      );
    } else if (index == 1) {
      showDialog(
        barrierDismissible: false,
        context: context,
        builder: (context) {
          return DialogWidget(
            contentWidget: BluetoothSettingDialog(
              bluetoothName: "友情提示",
              okBtnTap: () {
                print(
                  "输入框中的文字为:${nameController.text}",
                );
              },
              vc: nameController,
              cancelBtnTap: () {},
            ),
          );
        },
      );
    } else {
      showDialog(
        context: context,
        barrierDismissible: false,
        builder: (context) {
          return ClockDialog();
        },
      );
    }
  }

  switchValue(bool value) {}
}
